from django.db import models

# Create your models here.


class BaseModel(models.Model):
    create_date = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    is_delete = models.BooleanField(verbose_name="是否删除", default=False)
    class Meta:
        abstract = True


# 操作日志
class Operate_LogModel(BaseModel):
    name = models.CharField(verbose_name="操作信息", max_length=64)
    staff_id = models.BigIntegerField(verbose_name="操作员工")
    path = models.CharField(verbose_name="操作路径", max_length=256)
    ip = models.CharField(verbose_name="登录ip", max_length=15)
    address = models.CharField(verbose_name="地点", max_length=256)
    facility = models.CharField(verbose_name="设备", max_length=256)
    class Meta():
        db_table="operate_log_tb"
        verbose_name = "操作日志表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"员工id{self.staff_id}，路径{self.path}"


# 权限角色表
class RoleModel(BaseModel):
    name = models.CharField(verbose_name="权限角色名称", max_length=30)
    desc = models.CharField(verbose_name="简介", max_length=256, null=True, blank=True)
    class Meta():
        db_table="role_tb"
        verbose_name = "权限角色表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 角色菜单表
class Role_MenuModel(BaseModel):
    role_id = models.BigIntegerField(verbose_name="角色id")
    menu_id = models.BigIntegerField(verbose_name="菜单id")
    class Meta():
        db_table="role_menu_tb"
        verbose_name = "角色菜单中间表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return f"角色{self.role_id}，菜单{self.menu_id}"


# 菜单表
class MenuModel(BaseModel):
    name = models.CharField(verbose_name='菜单名称', max_length=30)
    path = models.CharField(verbose_name='菜单地址', max_length=256)
    icon = models.CharField(verbose_name='菜单图标', max_length=256, null=True, blank=True)
    order = models.IntegerField(verbose_name="排序")
    menu_id = models.BigIntegerField(verbose_name="上级菜单id", null=True, blank=True)
    class Meta:
        db_table = 'menu_tb'
        verbose_name_plural = "菜单表"
    def __str__(self):
        return self.name


# 权限表
class PermissionModel(BaseModel):
    name = models.CharField(verbose_name='权限名称', max_length=30)
    path = models.CharField(verbose_name='权限', max_length=256)
    class Meta:
        db_table = 'permission_tb'
        verbose_name_plural = "权限表"
    def __str__(self):
        return self.name


# 部门表
class DepartmentModel(BaseModel):
    name = models.CharField(verbose_name="部门名称", max_length=30)
    desc = models.CharField(verbose_name="简介", max_length=256, null=True, blank=True)
    staff_id = models.BigIntegerField(verbose_name="部门负责人id", null=True, blank=True)
    department_id = models.BigIntegerField(verbose_name="上级部门id", null=True, blank=True)
    class Meta():
        db_table="department_tb"
        verbose_name = "部门表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# 职级表
class RankModel(BaseModel):
    name = models.CharField(verbose_name="职级名称", max_length=30)
    desc = models.CharField(verbose_name="简介", max_length=256, null=True, blank=True)
    class Meta():
        db_table="rank_tb"
        verbose_name = "职级表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name


# # 职位角色中间表
# class Position_RoleModel(BaseModel):
#     role_id = models.BigIntegerField(verbose_name="角色id")
#     position_id = models.BigIntegerField(verbose_name="职位id")
#     class Meta():
#         db_table="position_role_tb"
#         verbose_name = "职位角色中间表"
#         verbose_name_plural = verbose_name
#     def __str__(self):
#         return f"角色{self.role_id}，职位{self.position_id}"


# 岗位表
class PositionModel(BaseModel):
    name = models.CharField(verbose_name="职位名称", max_length=30)
    rank_id = models.BigIntegerField(verbose_name="职级id")
    department_id = models.BigIntegerField(verbose_name="部门id")
    desc = models.CharField(verbose_name="简介", max_length=256, null=True, blank=True)
    class Meta():
        db_table="position_tb"
        verbose_name = "职位表"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.name